﻿namespace ScrumLite.WebUx
{
    using System;
    using System.Web.Mvc;
    using System.Web.Routing;

    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);

        }

        private static void RegisterRoutes(RouteCollection routes)
        {
            //Home
            routes.Add(new Route("Default.aspx", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Home",
                    action = "Index"
                }),
            });

            // Projects
            routes.Add(new Route("Projects", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "List"
                }),
            });

            routes.Add(new Route("Projects/List", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "List"
                }),
            });

            routes.Add(new Route("Projects/ListHistoric", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "ListHistoric"
                }),
            });

            routes.Add(new Route("Projects/New", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "New"
                }),
            });

            routes.Add(new Route("Projects/Save", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "Save"
                }),
            });

            routes.Add(new Route("Projects/{projectName}/Edit", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "Edit",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Projects/{projectName}/{roleId}/Abilities", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "Abilities",
                    projectName = (string)null,
                    roleId = (string)null
                }),
            });

            routes.Add(new Route("Projects/{projectName}/RemovePerson/{personId}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "RemovePerson",
                    projectName = (string)null,
                    personId = (string)null
                }),
            });

            routes.Add(new Route("Projects/{projectName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Projects",
                    action = "Home",
                    projectName = (string)null
                }),
            });

            // Reviews
            routes.Add(new Route("Reviews/{projectName}/Edit/{Id}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Reviews",
                    action = "Edit",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Reviews/{projectName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Reviews",
                    action = "List",
                    projectName = (string)null
                }),
            });

            // Requests
            routes.Add(new Route("Requests/{projectName}/Read/{mode}/{workArea}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "Read",
                    projectName = (string)null,
                    mode = "Opened",
                    workArea = String.Empty
                }),
            });

            routes.Add(new Route("Requests/{projectName}/Write", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "Write",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Requests/{projectName}/ReadOne/{moniker}/{gridPage}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "ReadOne",
                    projectName = (string)null,
                    gridPage = 0
                }),
            });

            routes.Add(new Route("Requests/{projectName}/Classify/{moniker}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "Classify",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Requests/{projectName}/ReadWorkArea/{moniker}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "ReadWorkArea",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Requests/{projectName}/WriteWorkArea/{moniker}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "WriteWorkArea",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Requests/{projectName}/Delete/{requestId}/{gridPage}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "Delete",
                    projectName = (string)null,
                    gridPage = 0
                }),
            });

            routes.Add(new Route("Requests/{projectName}/New/{gridPage}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    action = "New",
                    projectName = (string)null,
                    gridPage = 0
                }),
            });

            routes.Add(new Route("Requests/{projectName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Requests",
                    projectName = (string)null
                }),
            });

            // Commitments
            routes.Add(new Route("Commitments/{projectName}/{action}/{Date}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Commitments",
                    action = "Home",
                    projectName = (string)null,
                    Date = DateTime.Now.Date
                }),
            });

            routes.Add(new Route("Commitments/{projectName}/CommitmentsMetrics", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Commitments",
                    action = "CommitmentsMetrics",
                    projectName = (string)null
                }),
            });

            // Deliverables
            routes.Add(new Route("Deliverables/{projectName}/Edit/{Id}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Deliverables",
                    action = "Edit",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Deliverables/{projectName}/ListByWorkArea/{WorkAreaName}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Deliverables",
                    action = "ListByWorkArea",
                    projectName = (string)null,
                    workAreaName = string.Empty
                }),
            });

            routes.Add(new Route("Deliverables/{projectName}/Save", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Deliverables",
                    action = "Save",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Deliverables/{projectName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Deliverables",
                    action = "Home",
                    projectName = (string)null
                }),
            });

            // WorkAreas
            routes.Add(new Route("WorkAreas/{projectName}/Edit/{Name}/{Id}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "WorkAreas",
                    action = "Edit",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("WorkAreas/{projectName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "WorkAreas",
                    action = "List",
                    projectName = (string)null
                }),
            });

            // Defects
            routes.Add(new Route("Defects/{projectName}/Read/{mode}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "Read",
                    projectName = (string)null,
                    mode = "Opened"
                }),
            });

            routes.Add(new Route("Defects/{projectName}/ReadByDeliverable/{deliverableId}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "ReadByDeliverable",
                    projectName = (string)null,
                    deliverableId = (string)null
                }),
            });

            routes.Add(new Route("Defects/{projectName}/ReadOne/{moniker}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "ReadOne",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Defects/{projectName}/New/{Triaged}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "New",
                    projectName = (string)null,
                    Triaged = 1
                }),
            });

            routes.Add(new Route("Defects/{projectName}/Write", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "Write",
                    projectName = (string)null
                }),
            });

            routes.Add(new Route("Defects/{projectName}/DefectsMetrics", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Defects",
                    action = "DefectsMetrics",
                    projectName = (string)null
                }),
            });

            // People
            routes.Add(new Route("People/{PersonId}/Abilities", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "People",
                    action = "Abilities",
                    PersonId = (string)null
                }),
            });

            routes.Add(new Route("People/{PersonId}/Education", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "People",
                    action = "Education",
                    PersonId = (string)null
                }),
            });

            routes.Add(new Route("People/List", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "People",
                    action = "List"
                }),
            });

            //Measures
            routes.Add(new Route("Measures/{projectName}/{ProcessName}/{action}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Measures",
                    action = "Dashboard",
                    projectName = string.Empty,
                    ProcessName = string.Empty
                }),
            });

            routes.Add(new Route("Burndowns/{projectName}/BurndownsMetrics", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new
                {
                    controller = "Burndowns",
                    action = "BurndownsMetrics",
                    projectName = (string)null
                }),
            });

            // Generic route
            routes.Add(new Route("{controller}/{action}", new MvcRouteHandler()));
        }
    }
}